package com.mng.sink;

import com.mng.dto.SensorReading;

import java.sql.*;

public class MysqlCT {
    public static void main(String[] args) throws Exception {
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/flinksinktest?serverTimezone=GMT";
        String username = "root";
        String password = "1234";
        Connection connection = null;
        PreparedStatement ps = null;

        //加载驱动
        Class.forName(driver);
        //创建连接
        connection = DriverManager.getConnection(url, username, password);
        String sql = "select * from sensorinput;";
        //获取执行语句
        ps = connection.prepareStatement(sql);
        ResultSet resultSet = ps.executeQuery();
        while(resultSet.next()){
            SensorReading sensorReading = new SensorReading(
                    resultSet.getString("id"),
                    resultSet.getLong("timestamp"),
                    resultSet.getDouble("temperaturre")
            );
            System.out.println(sensorReading);
        }
        connection.close();
        ps.close();

    }
}
